package utils

import "fmt"

// build a ethpool , ethX is interface name where the X is a number between 1-255
type EthPool struct {
	ethMap map[string]bool
	curEth int
}

func NewEthPool() *EthPool {
	return &EthPool{
		ethMap: make(map[string]bool),
		curEth: 1,
	}
}

func (p *EthPool) ReSetEth() {
	p.curEth = 1
}

func (p *EthPool) NextEth() string {
	for {
		eth := fmt.Sprintf("eth%d", p.curEth)
		if p.curEth > 255 {
			return ""
		}
		if p.ethMap[eth] {
			p.curEth++
			continue
		} else {
			return eth
		}
	}
}

func (p *EthPool) IsEthInUse(eth string) bool {
	return p.ethMap[eth]
}

func (p *EthPool) AddEth(eth string) {
	p.ethMap[eth] = true
}

func (p *EthPool) DelEth(eth string) {
	delete(p.ethMap, eth)
}
